package com.maxd.controller;

import com.maxd.bean.PageRes;
import com.maxd.bean.evaluation.EvaluationReq;
import com.maxd.error.Result;
import com.maxd.error.ResultUtil;
import com.maxd.model.EvaluationRecord;
import com.maxd.model.StudentInfo;
import com.maxd.service.evaluation.IEvaluationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(value="学员评价", tags = {"学员评价"})
@RestController
@RequestMapping("/evaluation")
public class EvaluationController {

    @Autowired
    private IEvaluationService evaluationService;

    @GetMapping("wait-list")
    @ApiOperation("查询待评价学生列表")
    public List<StudentInfo> waitEvaluationList(@RequestParam("lessonId") Long lessonId) {
        return evaluationService.waitEvaluationList(lessonId);
    }

    @GetMapping("evaluation-page")
    @ApiOperation("分页查询评价记录列表")
    public Result<PageRes<EvaluationRecord>> evaluationPage(@ApiParam("页码，从0页开始") @RequestParam("pageNo") Integer pageNo,
                                            @ApiParam("每页记录数量") @RequestParam("pageSize") Integer pageSize,
                                            @ApiParam("课程ID") @RequestParam(required = false, name = "lessonId") Long lessonId,
                                            @ApiParam("学生ID") @RequestParam(required = false, name = "studentId") Long studentId,
                                            @ApiParam("评价人(教官或主理人)用户ID") @RequestParam(required = false, name = "userId") Long userId) {
        PageRes<EvaluationRecord> pageRes = evaluationService.queryPage(pageNo, pageSize, lessonId, studentId, userId);
        return ResultUtil.success(pageRes);
    }

    @GetMapping("evaluation-list")
    @ApiOperation("查询评价记录列表")
    public Result<List<EvaluationRecord>> evaluationList(@ApiParam("课程ID") @RequestParam(required = false, name = "lessonId") Long lessonId,
                                                 @ApiParam("学生ID") @RequestParam(required = false, name = "studentId") Long studentId,
                                                 @ApiParam("评价人(教官或主理人)用户ID") @RequestParam(required = false, name = "userId") Long userId) {
        List<EvaluationRecord> records = evaluationService.queryList(lessonId, studentId, userId);
        return ResultUtil.success(records);
    }

    @PostMapping("batch-evaluation")
    @ApiOperation("批量评价")
    public Result<Void> batchEvaluation(@RequestBody @Validated EvaluationReq req) {
        evaluationService.batchEvaluation(req);
        return ResultUtil.success();
    }
}
